package com.briup.cms.web.controller;

import com.briup.cms.bean.BaseUser;
import com.briup.cms.log.LoggingAccess;
import com.briup.cms.service.IBaseUserService;
import com.briup.cms.utils.Message;
import com.briup.cms.utils.MessageUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 这里的接口不需要认证
 **/
@Api(tags="登录相关接口")
@RestController
public class LoginController {

    @Autowired
    private IBaseUserService baseUserService;

    @ApiOperation(value = "用户登录")
    @ApiImplicitParams({
            @ApiImplicitParam(name="username",value="用户名",required = true,defaultValue = "admin1"),
            @ApiImplicitParam(name="password",value="密码",required = true,defaultValue = "123456"),
    })
    @PostMapping("/login")
    public Message login(String username,String password){
        String token = baseUserService.login(username,password);
        return MessageUtil.success(token);
    }

    @ApiOperation(value = "用户退出")
    @PostMapping("/logout")
    public Message logout(){
        return MessageUtil.success("退出成功");
    }

}
